<template>
	<view class="com-chat-apply">
		<!-- 會話申請14：申请 15同意  16拒绝 -->
		<block v-if="isDoctor">
			<div class="chat-item" v-if="msgItem.msn_type == 14">
				<view class="txt">{{msgItem.msn}}</view>
				<!-- 0申请中  1通过  2 拒绝 3未发起过 -->
				<div class="btn-box" v-if="msgItem.apply_status == 0">
					<button type="primary" size="mini" @click="clickAgree">同意</button>
					<button type="primary" size="mini" @click="clickreject">拒绝</button>
				</div>
			</div>
			<div class="chat-item" v-if="msgItem.msn_type == 15 || msgItem.msn_type == 16">
				<view class="txt">{{msgItem.msn}}</view>
			</div>

		</block>
		<block v-else>
			<div class="apply-item">
				<div class="txt">{{msgItem.msn}}</div>
			</div>
		</block>

	</view>
</template>

<script>
	export default {
		name: 'chat-apply',
		props: {
			isDoctor: {
				type: Boolean,
				default: false
			},
			msgItem: {
				type: Object,
				default: function() {
					return {}
				}
			}
		},
		data() {
			return {

			}
		},
		created() {
			//console.log(this.isDoctor,this.msgItem)
		},
		methods: {
			// 同意
			clickAgree() {
				// 0申请中  1通过  2 拒绝 3未發起過
				this.msgItem.apply_status = 1;
				// 會話申請14：申请 15同意  16拒绝
				this.$emit('chatReply', 15, this.msgItem);
			},
			// 拒絕
			clickreject() {
				let that = this;
				uni.showModal({
					title: '提示',
					content: '拒绝会话申请后,患者将无法回复信息,确认要拒绝吗?',
					success: function(res) {
						if (res.confirm) {
							that.msgItem.apply_status = 2;
							that.$emit('chatReply', 16, this.msgItem);
						} else if (res.cancel) {

						}
					}
				})
				
			},
		}
	}
</script>

<style lang="scss">
	.com-chat-apply {
		width: 100%;
	}
	// .txt{
	// 	font-size: 14px;
	// 	color:#323232;
	// }
	.chat-item {
		padding: 10px;

		.btn-box {
			display: flex;
			justify-content: space-evenly;
			width: 160px;
			margin-top: 10px;
		}
		
	}
</style>